﻿<?php

if(!defined('IN_PHPSCUP'))exit('hacking'); 
class ProtApp extends BaseApp
{

    var $type = 'prot';
	
    function index()
    {
        if(!isset($_POST['word']))
		{
		$_POST['word'] = '';
		}
        if(!isset($_GET['v']))
		{
		$_GET['v'] = '';
		}
	    $word = $_POST['word'];
		$word_array = explode(' ',$word);
		
		foreach($word_array as $key => $value)
		{
			if(!$value)
			{
             unset($word_array[$key]);
		    }  
		}
		 
        $order = '';
		$v = $_GET['v'];
		if($v == 'timeasc')
		{
        $order = 'A.add_time asc';
		}
		else if($v == 'timedesc')
		{
        $order = 'A.add_time desc';		
		}
		else if($v == 'showyes')
		{
        $order = 'A.is_show desc';		
		}
		else if($v == 'showno')
		{
        $order = 'A.is_show asc';		
		}
		else if($v == 'topyes')
		{
        $order = 'A.is_top desc';		
		}
		else if($v == 'topno')
		{
        $order = 'A.is_top asc';		
		}
		else if($v == 'recyes')
		{
        $order = 'A.is_recommend desc';		
		}
		else if($v == 'recno')
		{
        $order = 'A.is_recommend asc';		
		}
		else if($v == 'indexyes')
		{
        $order = 'A.is_index desc';		
		}
		else if($v == 'indexno')
		{
        $order = 'A.is_index asc';		
		}
				
	
	
	
		$TB_new = &$this->_model('prot');
				
		$data = $TB_new->show($order,$v,$word_array);	
			
        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);	
		
		
	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
		if(!is_array($categorydata))
		{
		 $categorydata = (array)$categorydata;
		}
		$categorylist = array();
		foreach($categorydata as $value)
		{
		    $categorylist[$value['cat_id']] = $value['cat_name'];
		}		
		
        $this->assign('categorylist', $categorylist);							
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		$this->assign('word', $word);
		$this->assign('v', $v);
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('prot_list.view.html');
    }


    function kindeditor()
    {
		 if(!isset($_GET['w']))
	 {
	 $_GET['w']='';
	 }
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");		
	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/admin/index.php?app=prot&act=kindeditorupfile&w='.$w));
	$kindeditor->show();
	
    }
	
    function kindeditorupfile()
    {
		 if(!isset($_GET['w']))
	 {
	 $_GET['w']='';
	 }
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/admin/index.php?app=prot&act=kindeditorupfile&w='.$w));
	$kindeditor->upfile('prot/'.$w);
	
    }
	
	

    function cagryadd()
    {
		$GLOBALS['Lang']->_get_lang('prot');	
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		
		$catgystr = $category->html_format_category($catgydata,0);	

        $this->assign('catgystr', $catgystr);	
		
        $this->assign('category_value', $this->type);
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('cagryadd.view.html');
    }
	
    function editcatgy()
    {
		$GLOBALS['Lang']->_get_lang('prot');	
		$id= intval($_GET['id']);
		
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		
		$data = $category->oneshow($id);
		
		$catgystr = $category->html_format_category($catgydata,$data['parent_id'],0,0,$id);

        $this->assign('data', $data);

        $this->assign('catgystr', $catgystr);
		
        $this->assign('category_value', $this->type);
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('cagryedit.view.html');
    }
	
    function cagrylist()
    {
		$GLOBALS['Lang']->_get_lang('prot');		
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		$catgydata = $category->get_list_category($catgydata);

		
        $this->assign('catgydata', $catgydata);				

        $this->assign('category_value', $this->type);
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('cagrylist.view.html');
    }

    function cyaddpost()
    {

	     $data = $_POST['data'];
         
		 $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		 $category->post($data);
		 
		 $category->write_cache($this->type);	
		 	 		 
		 $this->cagrylist();

    }


    function cyeditpost()
    {

	     $id = $_POST['id'];

	     $data = $_POST['data'];
         
		 $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		 $category->editaction($id,$data);

		 $category->write_cache($this->type);	
		 	 		 
		 $this->cagrylist();

    }

    function delcatgy()
    {
		$id= intval($_GET['id']);		

	    $category = & $GLOBALS['SCup']->_get_category();		 		 		
		$category->del($id);
		
		$category->write_cache($this->type);
				      
		$this->cagrylist();   
    }	
		

    function upfile()
    {
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	 if(!isset($_GET["edit"]))
	 {
	 $_GET["edit"]='';
	 }	 
	 if(!isset($_GET["picurl"]))
	 {
	 $_GET["picurl"]='';
	 }			
		$action = $_POST["action"];
		
		$id = intval($_GET['id']);
		
		$edit = $_GET["edit"];
		$picurl = $_GET["picurl"];
		if($edit)
		{
        $this->assign('edit', $edit);		
		}
        if($picurl)
		{
        $this->assign('picurl', $picurl);
		}

						
		if($action == 'post')
		{
				if(!$_FILES['postfile1']['tmp_name']){
					$id || $id = intval($_POST['id']);	
					echo '<script> alert("请选择上传的图片");</script>';	
				}else{
	        if(!isset($_POST["edit"]))
	        {
	         $_POST["edit"]='';
	        }	 
	        if(!isset($_POST["picurl"]))
	        {
	         $_POST["picurl"]='';
	        }
	       if(!isset($_POST['id']))
	       {
	        $_POST['id']='';
	        }			
		       $edit = $_POST["edit"];
		       $picurl = $_POST["picurl"];
		 	   $id || $id = intval($_POST['id']);		

		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile('prot/'.$id); 	  
	           $updata = $upfile->_batch_upfile('prot');		 

		       $newfile = $updata[1]['path'];
		       
			   if($edit=='editp' && $picurl)
			   {
			   
			          $TB_new = &$this->_model('prot');			    		 		 		
		              $TB_new->editpicurl($id,array('picurl'=>$newfile));
					  
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		              del_file($pic_dir);				   
			   }
			   
			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		              del_file($pic_dir);			 
		       }
		 	   
			
		
		      $pic_url = SITE_URL . '/' . UPFILE_PATH . '/' .$newfile;

	    echo "<img src='{$pic_url}' id='upsrc' width='100px' height='100px'><br/><A HREF='?app=prot&act=upfile&edit=edit&picurl=$newfile&id=$id'>修改图片</A>";
	     
		$jsfun="upfile";
	    echo "<script>
				if(self==top){
					window.opener.$jsfun('$newfile','uppic');
					window.self.close();
				}else{
					window.parent.$jsfun('$newfile','uppic');
				}
		     </script>";
				
	    exit;
		
			}
		}

        $this->assign('id', $id);
	    $this->assign('app', $this->type);					    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
        $this->assign('edit',$edit);
        $this->assign('picurl',$picurl);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('upfile.view.html');
    }



    function pupfile()
    {	
	 if(!isset($_GET["action"]))
	 {
	 $_GET["action"]='';
	 }
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	        if(!isset($_POST['id']))
	        {
	          $_POST['id']='';
	        }  
		$action = $_GET["action"];			
		$action || $action = $_POST["action"];
		
		$id = intval($_GET['id']);
		$cid =$id;
				
		if($action == 'post')
		{
				$id || $id = intval($_POST['id']);		
	      $cid = $id;
				if(!$_FILES['postfile1']['tmp_name']){
					echo '<script> alert("请选择上传的图片");</script>';
				}else{
			       include(ROOT_PATH.'/lib/upfile.lib.php');	  
		           $upfile = new Upfile('prot/'.$id); 	  
		           $updata = $upfile->_batch_upfile('prot');		 
			 		 
			       $newfile = $updata[1]['path'];
				   
	               unset($data);
			       $data['uid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];		       
	               $data['con_id'] = $id;
				   $data['file_url'] = $updata[1]['path'];
				   $data['size'] = $updata[1]['size'];
				   $data['type'] = $updata[1]['type'];
				   			   
				   $TB_new = &$this->_model('upfile');			    		 		 		
			     $TB_new->post($data);
		     }
					   	   
	    }
		else if($action == 'del')
		{
			   $id || $id = intval($_POST['id']);   
			   $TB_new = &$this->_model('upfile');
			   
			    $picdata = $TB_new->oneshow($id);
				$picurl = $picdata['file_url'];
                $cid = $picdata['con_id'];
			   			    		 		 		
		       $TB_new->del($id);
					  
		       $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		       del_file($pic_dir);			
		
		}			

	    $TB_new = &$this->_model('upfile');

        $this->assign('picdata', $TB_new ->selct($cid));		
	
        $this->assign('id', $cid);
	    $this->assign('app', $this->type);					    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('pupfile.view.html');
    }



    function edit()
    {	
		$id= intval($_GET['id']);
		
		$TB_new = &$this->_model('prot');
				
		$data = $TB_new->oneshow($id);	
		$data['content'] = str_replace("'", "&rsquo;", $data['content']);				
        $this->assign('keyworddata', del_empty_var_1(explode('+', AWAY_USE_KEYWORD)));	
        $this->assign('zhandian', del_empty_var(explode('+', AWAY_USE_ZHANDIAN)));
	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
		
        $this->assign('categorydata', $categorydata);

        $this->assign('data', $data);
        $this->assign('id', $id);
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('prot_edit.view.html');   
    }

    function add()
    {	
	
	
		$TB_new = &$this->_model('prot'); 
		
		$id_array = $TB_new->select_id();		
		foreach($id_array as $value)
		{
		 del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' . $value['id'] . '/');	
		}		
		$TB_new->delet_id();	
		
				
		$data_id = $TB_new->insert_id();

		
        $this->assign('id', $data_id);	
				
        $this->assign('keyworddata', del_empty_var_1(explode('+', AWAY_USE_KEYWORD)));	
        $this->assign('zhandian', del_empty_var(explode('+', AWAY_USE_ZHANDIAN)));		
	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
		   
        $this->assign('categorydata', $categorydata);	
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('prot_add.view.html');
    }


    function addpost()
    {
        
	     $data = $_POST['data'];
		 $id = $_POST['id'];
         if(!isset($data['cat_id'])||empty($data['cat_id']))
		{
		 $notice = &get_message(array('msg'=>"所属栏目不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }
		 			 		 
		 $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		 $data['user_name'] = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];	 
		/* $data['config'] = serialize(array('titlecolor'=>$data['titlecolor'],'fonttype'=>$data['fonttype']));*/
         $data['config'] = serialize(array('titlecolor'=>'','fonttype'=>''));
		 if(empty($data['yz']))
		 {
		    $data['yz']='0';
		 }  
		 if(empty($data['top']))
		 {
		    $data['top']='0';
		 }  
		 if(empty($data['levels']))
		 {
		    $data['levels']='0';
		 }  
		 if(empty($data['special']))
		 {
		    $data['special']='0';
		 }  		 

		 /*$category = & $GLOBALS['SCup']->_get_category();
		 $tmp_info=$category->oneshow($data['cat_id']);*/
		 $data['parent_id']=get_parent_id($data['cat_id']);

		 $TB_new = &$this->_model('prot'); 
		 		 		
		 $TB_new->post($id,$data);

/**/		$view = &get_view();
	    $view->html($id,SITE_URL ."/?app=prot&act=show&id=".$id."&langid=".trim($GLOBALS['Lang']->_lang_tp),'prot');					 
		 $this->index();
    }


    function editpost()
    {

		$id= intval($_POST['id']);
		
		$data = $_POST['data'];
          if(!isset($data['cat_id'])||empty($data['cat_id']))
		{
		 $notice = &get_message(array('msg'=>"所属栏目不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }
		 	
 		 $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		 $data['user_name'] = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];	 
		/* $data['config'] = serialize(array('titlecolor'=>$data['titlecolor'],'fonttype'=>$data['fonttype']));*/
         $data['config'] = serialize(array('titlecolor'=>'','fonttype'=>''));
		 if(empty($data['yz']))
		 {
		    $data['yz']='0';
		 }  
		 if(empty($data['top']))
		 {
		    $data['top']='0';
		 }  
		 if(empty($data['levels']))
		 {
		    $data['levels']='0';
		 }  
		 if(empty($data['special']))
		 {
		    $data['special']='0';
		 }

		 /*$category = & $GLOBALS['SCup']->_get_category();
		 $tmp_info=$category->oneshow($data['cat_id']);*/
		 $data['parent_id']=get_parent_id($data['cat_id']);
		 
 
 		$TB_new = &$this->_model('prot');  
				
		$TB_new->editaction($id,$data);

/**/		$view = &get_view();
	    $view->html($id,SITE_URL ."/?app=prot&act=show&id=".$id."&langid=".trim($GLOBALS['Lang']->_lang_tp),'prot');		
		$this->index();  
		 

    }
    function lcsort()
    {
		$id= intval($_GET['id']);
		$v= intval($_GET['v']);		
        unset($data);
		$data['sort_order'] = $v;
		
	    $category = & $GLOBALS['SCup']->_get_category();		 		 		
		$category->editsort($id,$data);
		
		$category->write_cache($this->type);	
					      
		$this->cagrylist();   
    }	

    function del()
    {

		$id= intval($_GET['id']);	
		del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' . $id. '/');			
			
		$TB_new = &$this->_model('prot');
		
		$TB_new->del($id);

		$view = &get_view();
	    $view->delhtml($id,'prot');						  

        $this->index();   

    }



  
}

?>